<?php

namespace app\admin\service\common;

class RSAEncryptService
{


    /**
     * 提交的数据解密
     * 根据配置的字段，前端提交时自动加密，后端收到自动解密
     * 如无需加密，请修改配置中加密字段为空
     * @param $postData
     * @return array
     */
    public static function decrypt($postData): array
    {
        $encryptFields = config('rds.encrypt_fields');
        if (in_array('*', $encryptFields)) {
            foreach ($postData as $key => $value) {
                if (is_string($value)) {
                    $postData[$key] = \utils\crypt\Crypt::decrypt($value);
                }
            }
        } else {
            foreach ($encryptFields as $field) {
                if (isset($postData[$field]) && is_string($postData[$field])) {
                    $postData[$field] = \utils\crypt\Crypt::decrypt($postData[$field]);
                }
            }
        }
        return $postData;
    }

}